<template>
<h1>个人中心</h1>
<div v-for="(weibo,i) in arr">
  <h3>{{weibo.content}}
    <el-button link @click="del(weibo.id,i)">删除</el-button>
  </h3>
</div>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
const  arr = ref([]);
const del=(id,i)=>{
  if (confirm("您确认删除此微博吗?")){
    axios.post('http://localhost:8080/v1/weibos/'+id+'/delete')
    .then((response)=>{
      if (response.data.code==2001){
        ElMessage.success("删除成功!");
        arr.value.splice(i,1);
      }
    })

  }
}
onMounted(()=>{
  //请求当前登录用户发布的所有微博
  let user = localStorage.user?JSON.parse(localStorage.user):null;
  axios.get('http://localhost:8080/v1/weibos?id='+user.id)
  .then((response)=>{
    if (response.data.code==2001){
      arr.value = response.data.data;
    }
  })
})
</script>

<style scoped>

</style>